package com.qf.serviceimpl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 路由策略
 *
 * @author Ypl
 * @version V1.0
 * @Project OctoberAndNovember
 * @Package com.qf.serviceimpl
 * @Description:
 * @Date 2022/11/10 10:52
 */
@Service(value = "router")
@Slf4j
public class RouterFilterServiceImpl implements FilterChainService {

    @Autowired
    AmqpAdmin amqpAdmin;
    @Autowired
    RabbitTemplate rabbitTemplate;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.debug("【路由策略】 开始执行");
        //获取运营商ID
        Integer operatorId = standardSubmit.getOperatorId();
        //队列名称
        String queueName = RabbitMQConstants.TOPIC_SMS_GATEWAY+operatorId;
        //创建队列
        amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
        //推送消息到达队列
        rabbitTemplate.convertAndSend(queueName,standardSubmit);
        log.debug("【路由策略】 执行成功");
        return true;
    }
}
